﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class CharacterInfo: ActorInfo
{


    public int coin { get;  set; }
    public WeaponType weaponType = WeaponType.Archer;
    [NonSerialized]
    public Action<int, int> onCoinChange;

    public CharacterInfo(int id, string name, int hp, float moveSpeed, int attack) :base(id,name,hp,moveSpeed,attack)
    {
        coin = 10;
    }

    /// <summary>
    /// 花钱
    /// </summary>
    /// <param name="count"></param>
    /// <returns></returns>
    public bool TakeCoin(int count)
    {
        if (coin<count)
        {
            return false;
        }
        int oldcoin = coin;
        coin -= count;
        if (oldcoin != coin)
        {
            if (onCoinChange!=null)
            {
                onCoinChange(oldcoin, coin);
            }
          
        }
        return true;
    }
    /// <summary>
    /// 得钱
    /// </summary>
    /// <param name="count"></param>
    public void AcquireCoin(int count)
    {
        int oldcoin = coin;
        coin += count;
        if (oldcoin != coin)
        {
            if (onCoinChange != null)
            {
                onCoinChange(oldcoin, coin);
            }
        }
    }
}
